package com.linxiao.call.controller;

import com.linxiao.call.domain.CrmOutDeptPhoneNo;
import com.linxiao.call.service.ICrmOutDeptPhoneNoService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 外呼号码配置Controller
 * 
 * @author zhoudong
 * @date 2022-05-17
 */
@RestController
@RequestMapping("/crm/outphoneno")
public class CrmOutDeptPhoneNoController extends BaseController
{
    @Autowired
    private ICrmOutDeptPhoneNoService crmOutDeptPhoneNoService;

    /**
     * 查询外呼号码配置列表
     */
    @PreAuthorize("@ss.hasPermi('crm:outphoneno:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmOutDeptPhoneNo crmOutDeptPhoneNo)
    {
        startPage();
        List<CrmOutDeptPhoneNo> list = crmOutDeptPhoneNoService.selectCrmOutDeptPhoneNoList(crmOutDeptPhoneNo);
        return getDataTable(list);
    }

    /**
     * 导出外呼号码配置列表
     */
    @PreAuthorize("@ss.hasPermi('crm:outphoneno:export')")
    @Log(title = "外呼号码配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmOutDeptPhoneNo crmOutDeptPhoneNo)
    {
        List<CrmOutDeptPhoneNo> list = crmOutDeptPhoneNoService.selectCrmOutDeptPhoneNoList(crmOutDeptPhoneNo);
        ExcelUtil<CrmOutDeptPhoneNo> util = new ExcelUtil<CrmOutDeptPhoneNo>(CrmOutDeptPhoneNo.class);
        util.exportExcel(response, list, "外呼号码配置数据");
    }

    /**
     * 获取外呼号码配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('crm:outphoneno:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(crmOutDeptPhoneNoService.selectCrmOutDeptPhoneNoById(id));
    }

    /**
     * 新增外呼号码配置
     */
    @PreAuthorize("@ss.hasPermi('crm:outphoneno:add')")
    @Log(title = "外呼号码配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmOutDeptPhoneNo crmOutDeptPhoneNo)
    {
        return toAjax(crmOutDeptPhoneNoService.insertCrmOutDeptPhoneNo(crmOutDeptPhoneNo));
    }

    /**
     * 修改外呼号码配置
     */
    @PreAuthorize("@ss.hasPermi('crm:outphoneno:edit')")
    @Log(title = "外呼号码配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmOutDeptPhoneNo crmOutDeptPhoneNo)
    {
        return toAjax(crmOutDeptPhoneNoService.updateCrmOutDeptPhoneNo(crmOutDeptPhoneNo));
    }

    /**
     * 删除外呼号码配置
     */
    @PreAuthorize("@ss.hasPermi('crm:outphoneno:remove')")
    @Log(title = "外呼号码配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(crmOutDeptPhoneNoService.deleteCrmOutDeptPhoneNoByIds(ids));
    }

    /**
     * 获取外显号码
     * @param mobile 客户手机号
     * @return
     */
    @GetMapping("/getShowPhoneNo")
    public AjaxResult getShowPhoneNo(@RequestParam String mobile) {
        return AjaxResult.success(crmOutDeptPhoneNoService.selectShowPhoneNo(mobile));
    }


    /**
     * 获取外显号码根据部门ID
     * @return
     */
    @GetMapping("/getShowPhoneNoByDeptId")
    public AjaxResult getShowPhoneNoByDeptId() {
        AjaxResult ajaxResult = crmOutDeptPhoneNoService.getShowPhoneNoByDeptId();
        return ajaxResult;
    }
    /**
     * 清空轮训队列
     * @param mobile 客户手机号
     * @return
     */
    @GetMapping("/clearShowPhoneIndex")
    public AjaxResult clearShowPhoneIndex(@RequestParam String mobile) {
        return AjaxResult.success(crmOutDeptPhoneNoService.clearShowPhoneIndex(mobile));
    }
}
